package com.example.administrator.printoutindemo.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.SaomiaoActivity;
import com.example.administrator.printoutindemo.bean.ZhiliangquyangBean;
import com.example.administrator.printoutindemo.http.SPUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/9/10.
 */

public class QuyangAdapter extends BaseAdapter {

     Context context;
    List<ZhiliangquyangBean> mlists=new ArrayList<>();
    LayoutInflater inflater;
    public void shua(){
        mlists=new ArrayList<>();
        notifyDataSetInvalidated();
    }
    public QuyangAdapter(Context context, List<ZhiliangquyangBean> mlists) {
        this.context = context;
        this.mlists = mlists;
        this.inflater= LayoutInflater.from(context);
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return mlists.size();
    }

    @Override
    public Object getItem(int i) {
        return mlists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("LongLogTag")
    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null){
            Log.e("hh===============================","11111");
            view=getInflater().inflate(R.layout.zhiliangquyangitem,null);
            holder=new ViewHolder();
            holder.tv_qydz=view.findViewById(R.id.tv_qydz);
            holder.tv_qysl=view.findViewById(R.id.tv_qysl);
            holder.tv_wlmc=view.findViewById(R.id.tv_wlmc);
            holder.tv_dwgg=view.findViewById(R.id.tv_dwgg);
            holder.ll_qyitem=view.findViewById(R.id.ll_qyitem);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }
        if (mlists.get(i).getSimpleGetAddress()!=null){
            holder.tv_qydz.setText(mlists.get(i).getSimpleGetAddress());
        }
        if (mlists.get(i).getSpotnum()!=null){
            holder.tv_qysl.setText(mlists.get(i).getSpotnum());
        }
        if (mlists.get(i).getMaterial()!=null){
            holder.tv_wlmc.setText(mlists.get(i).getMaterial());
        }
        if (String.valueOf(mlists.get(i).getUnit())!=null){
            holder.tv_dwgg.setText(String.valueOf(mlists.get(i).getUnit()));
        }
       holder.ll_qyitem.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               SPUtil.putString(context,"qymid",mlists.get(i).getMid());
               Intent intent=new Intent(context, SaomiaoActivity.class);
               context.startActivity(intent);
           }
       });
//        holder.tv_cwxz.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
////                SPUtil.putInt(context,"dids",mlists.get(i).getDid());
////                SPUtil.putString(context,"shuliang", String.valueOf(mlists.get(i).getDnum()));
////                Intent intent=new Intent(context,CangKuActivity.class);
////                context.startActivity(intent);
//            }
//        });

//        Log.e("hh===============================",mlists.get(i).getProjectName());
        return view;
    }
    class ViewHolder{
        TextView tv_qydz,tv_qysl,tv_wlmc,tv_dwgg;
        LinearLayout ll_qyitem;
    }
    public  void addAll(List<ZhiliangquyangBean> sdc){
        mlists.addAll(sdc);
        notifyDataSetChanged();
    }
}
